package com.thd.kc.controller;

import com.thd.kc.dto.Message;
import com.thd.kc.utils.BasicException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.w3c.dom.html.HTMLBaseElement;

import javax.websocket.RemoteEndpoint;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class ExceptionAdviceController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @ExceptionHandler
    public Message handler(Exception e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        return Message.error(e.getMessage());
    }

    @ExceptionHandler
    public Message handler(RuntimeException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        return Message.error(e.getMessage());
    }

    @ExceptionHandler
    public Message handler(BasicException e) {
        logger.error(e.getMsg());
        e.printStackTrace();
        return Message.error(e.getMsg());
    }

}
